﻿
<!DOCTYPE html>

<html>
<head>
    <title></title>
</head>

<body>

    <form  action="/shop/Ajax_addPic" method="post" enctype="multipart/form-data">
        <div id="uploadElement">
            <div class="item">
                <input type="file" name="filedata"/><button type="button" onclick="myHtmlUpload.delEl(this)">del</button>
            </div>
        </div>
        <button type="button" onclick="myHtmlUpload.addEl()">增加</button>
    </form>
</body>
</html>
<script>
    var a = [1, 2, 3, 4, 5, 6, 7, 8];

    a.splice(1, 2); 
   // alert(a)
    var HtmlUpload = function () {
        this.init.apply(this, arguments); 
    }

    HtmlUpload.prototype.init = function (elsId) {
        this.elObjs = new Array();
        this.elsEl = document.getElementById(elsId)
        this.elObjs[0] = document.getElementById(elsId).firstChild;
        this.elTemp = document.getElementById(elsId).firstChild.cloneNode();
        this.elChildTemp = document.getElementById(elsId).firstChild.innerHTML;

    }
    HtmlUpload.prototype.addEl = function () {
        var _tem = this.elTemp.cloneNode()
        _tem.innerHTML = this.elChildTemp;
        this.elObjs[this.elObjs.length] = this.elsEl.appendChild(_tem);
    }
    HtmlUpload.prototype.delEl = function (it) {
        var index = this.elObjs.length - 1;

        if (index == 0) { return; }
        for (index; index >= 0; index--) {
            //alert(it.parentNode.innerHTML + "\n---\n" + this.elObjs[index].innerHTML)
            if (it.parentNode == this.elObjs[index]) {


               // debugger;
                this.elObjs.splice(index, index+1)
                it.parentNode.parentNode.removeChild(it.parentNode)

                return;
            }
        }
    }
    HtmlUpload.prototype.getElTemp = function () {
    }
    var myHtmlUpload = new HtmlUpload("uploadElement");



</script>